/*
 * 对账
 * @author 狮子
 * @time 2018/11/9
 * @since 1.0.0
 * */
// React基础组件
import React from 'react'
// dva 连接组件 - 连接route和model
import { connect } from 'dva'
// 引入antd的组件
import { Form } from 'antd'
//导入路由组件，用于跳转等
import { Link, hashHistory } from 'dva/router'
// 导入项目全局配置文件
import config from 'config/config'
import cx from 'classnames'
// 引入model取值工具方法
import { mapStateToProps } from 'utils/view_utils'
// 当前组件样式
import styles from './accountBalanceListStyle.less'
import ListPage from 'widget/PageTmpl/ListPage'


const routeView = function ({ dispatch, model, form }) {

  const { resetFields, getFieldDecorator, validateFields, setFieldsValue } = form
  const { modelObj, namespace } = model
  const { areaList, option } = modelObj
  // 资讯详情页跳转
  function detailSkip(type, id = '') {
    hashHistory.push({
      pathname: '/home/accountAdmin/accountBalanceDetail',
      query: { type, id }
    });
  }
  let pageProps = {
    // ---------- 界面部分 ----------
    ui: {
      // 页面接口地址
      api_url: "admin/estate/list",
      // 接口方式
      method: "POST",
      headers: {
        "Content-type": "application/json"
      },
      app: "",
      // 接口参数
      params: "pageNo=1&pageSize=10",
      // 模拟数据 - 用于开发需要，若填充了上面的api_url之后，请将此项设置为null
      // "mockData": mockData,
      mockData: null,
      // 查询栏
      search_bar: {
        fields: [

          {
            en_name: 'name',
            zh_name: '项目名称',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
          {
            en_name: 'activityName',
            zh_name: '活动名称',
            elem_type: 'Input',
            elem_valid_type: 'string',
          },
          {
            en_name: 'activityType',
            zh_name: '类型',
            elem_type: 'Select',
            elem_valid_type: 'string',
          },
          {
            en_name: "validTime",
            zh_name: "有效期",
            elem_type: "Date",
            format: "YYYY-MM-DD",
            // query_format: "YYYY-MM-DD HH:mm:ss",   // 请求参数, 当请求参数和显示时格式不同可通过该参数区分
            // double: true,  // 日期范围组件 使用"YYYY-MM-DD HH:mm:ss"格式时, 显示不全时可使用该参数, 将占据两格位置
            split_keys: ['startTime', 'expireDate'],
            elem_valid_type: "string"
          },

        ],
        searchHandler: (e) => { // 自定义搜索按钮回调函数，点击搜索时触发
          console.log('search click', e)
        },
        resetHandler: () => { // 自定义重置按钮回调函数，点击重置时触发
          console.log('reset click')
        },
        searchCallback: params => { // 自定义搜索完成后的后调函数, 搜索完成后触发, 并将本次搜索的参数传入
          console.log('search finish', params)
        },
        pasteTargetList: [  // 列表组件中将输入框的en_name作为默认id(也可以通过id另外设置)
          'carName',  // 将需要粘贴事件拦截的输入框id以数组的形式传入, 该参数对应PasteFromClipboard组件的targetList参数
        ]
      },
      // 数据表格
      table:
      {
        status_params: "status=0",
        status_text: "全部",
        // 表头字段列表
        scroll: { x: 1100 },
        fields: [
          {
            en_name: "key",
            zh_name: "序号",
            width: 60,
            render: (a, item, index, d, e, f) => {
              return index + 1
            },
          },
          {
            en_name: "estateCode",
            zh_name: "项目编号",
          },
          {
            en_name: "name",
            zh_name: "项目名称",
          },
          {
            en_name: "cityName",
            width:150,
            zh_name: "所属城市",
          },
          {
            en_name: "activityType",
            zh_name: "类型"
          },
          {
            en_name: "event",
            zh_name: "事件",
          },
          {
            en_name: "deposit",
            zh_name: "定金",
          },
          {
            en_name: "total",
            zh_name: "总笔数",
          },
          {
            en_name: "reconciliationDate",
            zh_name: "对账日期",
          },
          {
            en_name: "edit",
            zh_name: "操作",
            render: (a, item, index, d, e, f) => {
              return (
                <span>
                  <a onClick={() => detailSkip('check', item.productId)}>查看</a>{<span className="ant-divider" />}
                </span>
              )
            },
          },
        ]
      },
      action_bar: []
    },
  }
  if (!!modelObj.biz) {
    pageProps.biz = modelObj.biz
    pageProps.biz.syncBackCbf = (biz) => {
      console.log(biz)
      dispatch({
        type: `${namespace}/updateStore`,
        payload: { biz }
      })
    }
  }
  return (
    <div className={cx('pageLayout')}>
      <ListPage pageProps={pageProps} />
    </div>
  )
}
// 连接视图(view)和模型(model)
export default connect(mapStateToProps)(Form.create()(routeView))
